package com.example.wechatappbackend.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.wechatappbackend.common.CommonResponse;
import com.example.wechatappbackend.common.JsonMsg;
import com.example.wechatappbackend.entity.Activity;
import com.example.wechatappbackend.persistence.ActivityMapper;
import com.example.wechatappbackend.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("activityService")
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public JsonMsg getAllActivity() {
        QueryWrapper<Activity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 1);
        List<Activity> activityList = activityMapper.selectList(queryWrapper);
        if(activityList.isEmpty()){
            return new  JsonMsg("0","没有活动",activityList);
        }
        for(int i=0;i<activityList.size();i++)
        {
            if(activityList.get(i).getStatus() == 1){
                return new JsonMsg("1","SUCCESS",activityList.get(i));
            }
        }
        return new JsonMsg("1","没有活动",null);
    }
}
